import { reqFoodList, reqFoodCategory ,reqShopDetail,reqUpDateFoodDetail} from '@/api/food'

const state = {
  foodList: [],
  foodCategory: {},
  shopDetail:{}
}

const mutations = {
  RECEIVE_FOODLIST (state, foodList) {
    state.foodList = foodList
  },
  RECIEVE_FOODCATEGORY (state, foodCategory) {
    state.foodCategory = foodCategory
  },
  RECEIVE_SHOPDETAIL(state,shopDetail){
    state.shopDetail = shopDetail
  }
}

const actions = {

  async getFoodList({commit},{offset,limit=20,restaurant_id}){
      const result = await reqFoodList(offset,limit,restaurant_id)
      commit('RECEIVE_FOODLIST',result)
  },

  async getFoodCategory ({ commit }, category_id) {
    const result = await reqFoodCategory(category_id)
    // console.log(result)
    commit('RECIEVE_FOODCATEGORY', result)
  },

  async getShopDetail({commit},shopid){
    // console.log(shopid)
    const result = await reqShopDetail(shopid)
    commit('RECEIVE_SHOPDETAIL',result)
    // return result    // console.log(result)
  },

  // async reqUpDateFoodDetail({commit},newFood){
  //   await reqUpDateFoodDetail(newFood)
  // }
}

const getters = {

}
export default {
  state,
  mutations,
  actions,
  getters
}